﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

using H2.NET.Controls;
using H2.NET.Business;
using H2.NET.Data.Common;

namespace H2.NET.Web.Pages
{
    public partial class PCCM : TaskPage
    {
        #region 属性 Public
        private bool IsLoaded
        {
            get
            {
                return ViewState["IsLoaded"] == null ? false : (bool)ViewState["IsLoaded"];
            }
            set { ViewState["IsLoaded"] = value; }
        }
        #endregion

        #region 事件 Page_Load(页面加载)
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                INFO.Text = string.Format("<br/>表单正在被同事“{0}”抢占处理，拒绝提交！", RobUser);
                INFO.Visible = IsOverFlow;

                //InitDropDownList();
                bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;
                
                #region 发起步骤
                if (TaskAPI.IsInitiate)
                {
                    VD.Checked = true;
                }
                if ((TaskAPI.IsBeginStep&& TaskAPI.IsAllowSubmit))
                {
                   
                    SetColor();
                }
                InitDropDownList();
                #endregion

                #region 审批环节
                if (!TaskAPI.IsInitiate)
                {
                    #region 加载数据并显示
                    ccm_Cost_Center center = (ccm_Cost_Center.process == TaskAPI.Process & ccm_Cost_Center.incident == TaskAPI.Incident).ListFirst<ccm_Cost_Center>();
                    if (center != null)
                    {
                        SetDropDownListValue(Actions, center.Actions);
                        SetColor();
                        ApplicationNo.Text          = center.ApplicationNo;
                        VD.Checked                          = center.VD_Checked == "1"; 
                        SA.Checked                          = center.SA_Checked == "1";
                        
                        Actions.SelectedValue       = center.Actions;
                        SetDropDownListValue(DrpPriority, center.DrpPriority);
                        IS_CO_Area.Text             = center.IS_CO_Area;
                        IS_Cost_Center.Text         = center.IS_Cost_Center;
                        Vaild_From.Text             = center.Vaild_From;
                        Vaild_To.Text               = center.Vaild_To;
                        RE_Cost_Center.Text         = center.RE_Cost_Center;
                        RE_CO_Area.Text             = center.RE_CO_Area;
                        Name.Text                   = center.Name;
                        Description.Text            = center.Description;
                        Person_Responsible.Text     = center.Person_Responsible;
                        SetDropDownListValue(Cost_Center_Category, center.Cost_Center_Category);
                        Hierarchy_Area.Text         = center.Hierarchy_Area;
                        Company_Code.SelectedValue  = center.Company_Code;
                        SetDropDownListValue(Functional_Area, center.Functional_Area);
                        SetDropDownListValue(Currency, center.Currency);
                        SetDropDownListValue(Profit_Center, center.Profit_Center);
                        Record_Quantity.Checked     = center.Record_Quantity=="1";
                        Actual_Revenues.Checked     = center.Actual_Revenues == "1";
                        Plan_Revenues.Checked       = center.Plan_Revenues == "1";

                        Center_Group_CO_Area.Text           = center.Center_Group_CO_Area;
                        Cost_Center_Group.Text             = center.Cost_Center_Group;
                        SetDropDownListValue(Copy_Cost_Center_Group, center.Copy_Cost_Center_Group);
                        Copy_CO_Area.Text                   = center.Copy_CO_Area;
                        Center_Group_Name.Text              = center.Center_Group_Name;
                        Center_Group_Name_1.Text = center.Center_Group_Name_1;
                        Center_Group_Name_2.Text = center.Center_Group_Name_2;
                        Center_Group_Name_3.Text = center.Center_Group_Name_3;
                        Center_Group_Name_4.Text = center.Center_Group_Name_4;
                        Center_Group_Name_5.Text = center.Center_Group_Name_5;
                        //SetDropDownListValue(Center_Group_Name_1, center.Center_Group_Name_1);
                        //SetDropDownListValue(Center_Group_Name_2, center.Center_Group_Name_2);
                        //SetDropDownListValue(Center_Group_Name_3, center.Center_Group_Name_3);
                        //SetDropDownListValue(Center_Group_Name_4, center.Center_Group_Name_4);
                        //SetDropDownListValue(Center_Group_Name_5, center.Center_Group_Name_5);

                        SetDropDownListValue(DMO_DrpPriority, center.DMO_DrpPriority);
                        DMO_Arrpvoe_Creation_Number.Text = center.DMO_Arrpvoe_Creation_Number;
                        DMO_Arrpvoe_Creation_Time.Text = center.DMO_Arrpvoe_Creation_Time;
                        DMO_Maintain_Creation_Number.Text = center.DMO_Maintain_Creation_Number;
                        DMO_Maintain_Creation_Time.Text = center.DMO_Maintain_Creation_Time;
                        DMO_Check_Creation_Number.Text = center.DMO_Check_Creation_Number;
                        DMO_Check_Creation_Time.Text = center.DMO_Check_Creation_Time;
                        DMO_Arrpvoe_Revision_Number.Text = center.DMO_Arrpvoe_Revision_Number;
                        DMO_Arrpvoe_Revision_Time.Text = center.DMO_Arrpvoe_Revision_Time;
                        DMO_Maintain_Revision_Number.Text = center.DMO_Maintain_Revision_Number;
                        DMO_Maintain_Revision_Time.Text = center.DMO_Maintain_Revision_Time;
                        DMO_Check_Revision_Number.Text = center.DMO_Check_Revision_Number;
                        DMO_Check_Revision_Time.Text = center.DMO_Check_Revision_Time;
                    }
                    #endregion

                    if (VD.Checked && !SA.Checked)
                    {

                        VD_L.Visible = VD.Checked;
                    }
                    else if (SA.Checked && !VD.Checked)
                    {
                        SA_L.Visible = SA.Checked;
                        P_SA.Visible = true;
                        VD_L.Visible = false;
                        SA_L.Visible = true;
                        P_VD.Visible = false;
                    }

                    else if (VD.Checked && SA.Checked)
                    {
                        VD_L.Visible = VD.Checked;
                        SA_L.Visible = SA.Checked;
                        //P_SA.Visible = true;
                        VD_L.Visible = true;
                        SA_L.Visible = true;
                        //P_VD.Visible = true;
                    }


                    #region 审批项初始化
                    switch(TaskAPI.Step)
                    {
                        case "DMO Approve":
                        case "DMO Maintain":
                        case "DMO Check":
                            Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                            break;
                        case "Manager Approve":
                            Assessment1.Option.Add(new t_AssessmentOption("Approve", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));

                            break;
                    }
                    #endregion
                }
                #endregion

                SetDefaultValue();

                #region 设置控件禁启用
                //bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;

                SetEnable(flg, VD, SA, Actions,DrpPriority, Center_Group_Name_5,Center_Group_Name_4, Center_Group_Name_3, Center_Group_Name_2, Center_Group_Name_1, Center_Group_Name, Cost_Center_Group, Copy_Cost_Center_Group, Copy_CO_Area, IS_Cost_Center, Vaild_From, Vaild_To, RE_Cost_Center, RE_CO_Area, Name, Description, Person_Responsible, Cost_Center_Category,Functional_Area, Hierarchy_Area, Company_Code, Currency, Profit_Center);
                //SetEnable(TaskAPI.Step == "DMO Maintain", SAP_Code);
                SetEnable(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", DMO_DrpPriority,DMO_Arrpvoe_Creation_Number, DMO_Arrpvoe_Creation_Time, DMO_Maintain_Creation_Number, DMO_Maintain_Creation_Time, DMO_Check_Creation_Number, DMO_Check_Creation_Time, DMO_Arrpvoe_Revision_Number, DMO_Arrpvoe_Revision_Time, DMO_Maintain_Revision_Number, DMO_Maintain_Revision_Time, DMO_Check_Revision_Number, DMO_Check_Revision_Time);
                SetVisible(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", P_DMO);
                Assessment1.Enable = TaskAPI.IsAllowSubmit;
                SetVisible(TaskAPI.IsAllowSubmit, Send, Split);

                //if (TaskAPI.Step == "DMO Approve")
                //{
                //    SetForeColor(Color.Blue, DMO_DrpPriority_L);
                //}
                
                //if (TaskAPI.Step == "DMO Approve" & Actions.SelectedValue == "1")
                //{
                //    SetForeColor(Color.Blue, DMO_Arrpvoe_Creation_L);
                //}
                //if (TaskAPI.Step == "DMO Maintain" & Actions.SelectedValue == "1")
                //{
                //    SetForeColor(Color.Blue, DMO_Maintain_Creation_L);
                //}
                //if (TaskAPI.Step == "DMO Check" & Actions.SelectedValue == "1")
                //{
                //    SetForeColor(Color.Blue, DMO_Check_Creation_L);
                //}
                //if (TaskAPI.Step == "DMO Approve" & Actions.SelectedValue != "1")
                //{
                //    SetForeColor(Color.Blue, DMO_Arrpvoe_Revision_L);
                //}
                //if (TaskAPI.Step == "DMO Maintain" & Actions.SelectedValue != "1")
                //{
                //    SetForeColor(Color.Blue, DMO_Maintain_Revision_L);
                //}
                //if (TaskAPI.Step == "DMO Check" & Actions.SelectedValue != "1")
                //{
                //    SetForeColor(Color.Blue, DMO_Check_Revision_L);
                //}

                Attachment1.AllowDelete = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                Attachment1.AllowUpload = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                //InitTabs();
                #endregion

                #region 加深颜色
                string item = null;
                string value = null;
                foreach (Control cr in this.Controls)
                {
                    if (cr is DropDownList)
                    {
                        DropDownList tb = (DropDownList)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            item = tb.SelectedItem.Text;
                            value = tb.SelectedValue.ToString();
                            tb.Items.Clear();
                            tb.Items.Add(new ListItem(item, value));
                        }
                        tb.ForeColor = System.Drawing.Color.DimGray;
                    }
                }
                if (!flg || !TaskAPI.IsAllowSubmit)
                {

                    foreach (Control cr in P_VD.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_VD.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                    foreach (Control cr in P_SA.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                   
                }
            }
            #endregion
            
        }
        #endregion

        #region 事件 Send
        protected void Send_Click(object sender, EventArgs e)
        {
            try
            {
                #region 数据验证
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Check" || TaskAPI.Step == "DMO Approve") && TaskAPI.IsAllowSubmit) // 如果是退回的情况，不存在验证
                {
                    
                    List<string> vald_s = new List<string>();
                    vald_s.AddRange(DataValidation());
                    if (vald_s.Count > 0)
                    {
                        Anthem.Manager.AddScriptForClientSideEval(string.Format("ShowMessage(\"{0}\", {1});", CombineMessage(vald_s), vald_s.Count));
                        return;
                    }
                }
                #endregion

                #region 引擎传值
                if (TaskAPI.IsBeginStep)
                {
                    if (TaskAPI.IsInitiate)
                    {
                        ApplicationNo.Text        = Util.GenerateSequence(((object[])TaskAPI["PrefixNo"])[0].ToString() + "-" + System.DateTime.Now.ToString("yyMM"), "", 4);
                        TaskAPI.UserName          = UserAPI.UserName;
                        TaskAPI["ApplicationNo"]  = ApplicationNo.Text;
                        TaskAPI["ApplicatorName"] = UserAPI.UserFullName;
                        TaskAPI["Applicator"]     = UserAPI.UserName;
                        TaskAPI["Time"]           = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                        TaskAPI["ApplicatorEmail"] = UserAPI.Mail;
                        TaskAPI["Department"]     = UserAPI.Department;
                        TaskAPI["ServerName"] = Util.AppSettings("ServerName");
                    }

                    TaskAPI.Summary = (Actions.SelectedItem.Text.Split(',').Length >= 2 ? Actions.SelectedItem.Text.Split(',')[1].Trim() : Actions.Text)
                                    + " / " + ApplicationNo.Text + (VD.Checked ? " / Cost Center " : "") + (SA.Checked ? " / Cost Center Group " : "") ;
                    
                    TaskAPI["Actions"]        = Actions.SelectedValue;
                    TaskAPI["Remark_by_Initiator"] = Assessment1.Assessment.Remark;
                    TaskAPI["DrpPriority"] = DrpPriority.SelectedItem.Text;
                    

                    #region 从数据库取得流程步骤处理人
                    SortedList<string, string> rec_a = new SortedList<string, string>();

                    IList<mdc_Recipient> rec_s = (mdc_Recipient.process == TaskAPI.Process & (mdc_Recipient.distribute == Actions.SelectedValue | mdc_Recipient.distribute == "*") & mdc_Recipient.status == 1).List<mdc_Recipient>();
                    foreach (mdc_Recipient rec in rec_s)
                    {
                        if (!rec_a.ContainsKey(rec.Step))
                        {
                            rec_a.Add(rec.Step, rec.Recipient);
                            continue;
                        }

                        if (rec_a.Values[rec_a.IndexOfKey(rec.Step)].Contains(rec.Recipient))
                        {
                            continue;
                        }

                        rec_a[rec.Step] = rec_a.Values[rec_a.IndexOfKey(rec.Step)] + "," + rec.Recipient;
                    }

                    //步骤处理人赋值
                    for (int i = 0; i < rec_a.Keys.Count; i++)
                    {
                        TaskAPI["R_" + rec_a.Keys[i].Replace(" ", "_")] = rec_a.Values[i].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    }

                    m_OrgChart oc = (m_OrgChart.empID.In(m_OrgChart.dr2EmpID, m_OrgChart.winID == UserAPI.UserName)).ListFirst<m_OrgChart>();
                    if (oc != null)
                    {
                        TaskAPI["R_Manager_Approve"] = oc.WinID;
                    }

                    #endregion
                }
                else
                {
                    TaskAPI["ApproveResult"] = Assessment1.Assessment.Opinion;
                    TaskAPI["TaskID"]        = TaskAPI.TaskID;
                }

               

                #endregion

                #region 提交步骤
                bool flg=false;
                Storage.TransactionExecute(o =>
                {
                    #region “Fill in the form”步骤
                    if (TaskAPI.IsBeginStep)
                    {
                        ccm_Cost_Center center = new ccm_Cost_Center();
                        if ((ccm_Cost_Center.process == TaskAPI.Process & ccm_Cost_Center.incident == TaskAPI.Incident & ccm_Cost_Center.userName == UserAPI.UserName).Count<ccm_Cost_Center>() > 0)
                        {
                            center = (ccm_Cost_Center.process == TaskAPI.Process & ccm_Cost_Center.incident == TaskAPI.Incident & ccm_Cost_Center.userName == UserAPI.UserName).ListFirst<ccm_Cost_Center>();
                        }
                        else
                        {
                            center.Process       = TaskAPI.Process;
                            center.Incident      = TaskAPI.Incident;
                            center.UserName      = UserAPI.UserName;
                            center.UserFullName  = UserAPI.UserFullName;
                            center.ApplicationNo = ApplicationNo.Text;
                            center.Time          = System.DateTime.Now;
                            center.Status        = 0;
                            center.Department    = UserAPI.Department;
                        }

                        center.Actions       = Actions.SelectedValue;
                        center.DrpPriority = DrpPriority.SelectedValue;
                       
                        //center.Actions       = Actions.SelectedItem.Text;
                        center.VD_Checked = VD.Checked ? "1" : "0";
                        center.SA_Checked = SA.Checked ? "1" : "0";
                        //center.Actions = Actions.SelectedValue;
                        
                        
                        #region VD
                        if (VD.Checked)
                        {
                        center.IS_CO_Area = IS_CO_Area.Text;
                        center.IS_Cost_Center = IS_Cost_Center.Text;
                        center.Vaild_From = Vaild_From.Text;
                        center.Vaild_To = Vaild_To.Text;
                        center.RE_Cost_Center = RE_Cost_Center.Text;
                        center.RE_CO_Area = RE_CO_Area.Text;
                        center.Name = Name.Text;
                        center.Description = Description.Text;
                        center.Person_Responsible = Person_Responsible.Text;
                        center.Cost_Center_Category = Cost_Center_Category.SelectedValue;
                        center.Hierarchy_Area = Hierarchy_Area.Text;
                        center.Company_Code = Company_Code.SelectedValue;

                        center.Functional_Area = Functional_Area.SelectedValue;
                        center.Currency = Currency.SelectedValue;
                        center.Profit_Center = Profit_Center.SelectedValue;
                        center.Record_Quantity = Record_Quantity.Checked?"1":"0";
                        center.Actual_Revenues = Actual_Revenues.Checked ? "1" : "0";
                        center.Plan_Revenues = Plan_Revenues.Checked ? "1" : "0";
                        }
                        #endregion

                        #region SA
                        if (SA.Checked)
                        {
                            center.Center_Group_CO_Area = Center_Group_CO_Area.Text;
                            center.Cost_Center_Group = Cost_Center_Group.Text;
                            center.Copy_Cost_Center_Group = Copy_Cost_Center_Group.SelectedValue;
                            center.Copy_CO_Area = Copy_CO_Area.Text;
                            center.Center_Group_Name = Center_Group_Name.Text;
                            center.Center_Group_Name_1 = Center_Group_Name_1.Text;
                            center.Center_Group_Name_2 = Center_Group_Name_2.Text;
                            center.Center_Group_Name_3 = Center_Group_Name_3.Text;
                            center.Center_Group_Name_4 = Center_Group_Name_4.Text;
                            center.Center_Group_Name_5 = Center_Group_Name_5.Text;
                            
                        }
                        #endregion

                       

                        (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });

                        Storage.Save(Storage.Context1, center);
                    }

                    if (TaskAPI.IsBeginStep && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = new mdc_Priority();
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = new mdc_Priority();
                            pro.Process = TaskAPI.Process;
                            pro.Incident = TaskAPI.Incident;
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }

                    }


                    if ((TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check") && !string.IsNullOrEmpty(this.DMO_DrpPriority.SelectedValue) && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {

                        //mdc_Priority pro;
                        //pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                        //pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                        //Storage.Save(pro);
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }


                    }

                    #endregion

                    //#region “DMO Maintain”步骤
                    //if (TaskAPI.Step == "DMO Maintain")
                    //{
                    //    (ccm_Cost_Center.process == TaskAPI.Process & ccm_Cost_Center.incident == TaskAPI.Incident).Edit<ccm_Cost_Center>(p =>
                    //    {
                    //        p.SAP_Code = SAP_Code.Text;
                    //    }    
                    //    );
                    //}
                    //#endregion
                    #region “DMO Maintain”步骤
                    if (TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check")
                    {

                        TaskAPI["DMO_DrpPriority"] = DMO_DrpPriority.SelectedItem.Text;
                        (ccm_Cost_Center.process == TaskAPI.Process & ccm_Cost_Center.incident == TaskAPI.Incident).Edit<ccm_Cost_Center>(p =>
                        {
                           // p.SAP_Code = SAP_Code.Text;
                            p.DMO_DrpPriority = DMO_DrpPriority.SelectedValue;
                            p.DMO_Arrpvoe_Creation_Number = DMO_Arrpvoe_Creation_Number.Text;
                            p.DMO_Arrpvoe_Creation_Time = DMO_Arrpvoe_Creation_Time.Text;
                            p.DMO_Maintain_Creation_Number = DMO_Maintain_Creation_Number.Text;
                            p.DMO_Maintain_Creation_Time = DMO_Maintain_Creation_Time.Text;
                            p.DMO_Check_Creation_Number = DMO_Check_Creation_Number.Text;
                            p.DMO_Check_Creation_Time = DMO_Check_Creation_Time.Text;
                            p.DMO_Arrpvoe_Revision_Number = DMO_Arrpvoe_Revision_Number.Text;
                            p.DMO_Arrpvoe_Revision_Time = DMO_Arrpvoe_Revision_Time.Text;
                            p.DMO_Maintain_Revision_Number = DMO_Maintain_Revision_Number.Text;
                            p.DMO_Maintain_Revision_Time = DMO_Maintain_Revision_Time.Text;
                            p.DMO_Check_Revision_Number = DMO_Check_Revision_Number.Text;
                            p.DMO_Check_Revision_Time = DMO_Check_Revision_Time.Text;

                            //p.DMO_SalesSAP_Code = DMO_SalesSAP_Code.Text;
                        }
                        );
                    }
                    //if ((TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check")&& !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    //{
                    //    mdc_Priority pro;

                    //    pro = new mdc_Priority();
                    //    pro.Process = TaskAPI.Process;
                    //    pro.Incident = TaskAPI.Incident;
                      
                    //    pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                      
                    //    Storage.Save(pro);

                    //}
                    #endregion
                    Storage.Save(Assessment1.Assessment);    //审批意见

                    //多节点退回
                    if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                    {
                        Assessment1.SetAsReturn(true);
                        TaskAPI.DirectActive(Assessment1.JumpStep);
                    }
                    else
                    {
                        Assessment1.SetAsReturn(false);
                    }
                    Assessment1.SubmitTo();

                    flg = TaskAPI.Send();
                });

                //如果数据库写入成功且流程发起成功的情况，将业务表数据与流程实例号进行关联
                if (TaskAPI.IsInitiate)
                {
                    if (!string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == 0).Edit<mdc_Priority>(p => 
                    {
                             p.Incident = TaskAPI.Incident;
                          });
                    }
                    
                    
                    (ccm_Cost_Center.process == TaskAPI.Process & ccm_Cost_Center.incident == 0 & ccm_Cost_Center.userName == UserAPI.UserName).Edit<ccm_Cost_Center>(p => 
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Assessment.process == TaskAPI.Process & t_Assessment.incident == 0 & t_Assessment.assignedToUserName == UserAPI.UserName).Edit<t_Assessment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                }
                #endregion

                Send.Visible = false;
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Success + "',true)");
            }
            catch (Exception ex)
            {
                TaskDB.Log("", false, "调用NVA方法Send_Click出错：" + ex.ToString());
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Failed + "',false)");
            }
        }
        #endregion

        #region 复选框选中事件 CheckedChanged
        protected void VD_CheckedChanged(object sender, EventArgs e)
        {
            if (!VD.Checked && !SA.Checked)
            {
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('至少保留一个选择项！',false)");
                VD.Checked = true;
            }
            SetVisible(false, P_VD, P_SA);
            switch (((Anthem.CheckBox)sender).ID)
            {
                case "VD":

                    if (VD.Checked)
                    {

                        VD_L.Visible = VD.Checked;
                    }

                    break;
                case "SA":
                    if (SA.Checked)
                    {
                        SA_L.Visible = SA.Checked;
                    }
                    break;

               
            }

            InitTabs();
        }
        #endregion

        #region 事件 Actions 变换
        protected void Actions_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetColor();

            SetEnable((Actions.SelectedValue == "1" || Actions.SelectedValue == "2" || Actions.SelectedValue == "3" || Actions.SelectedValue == "4"), DrpPriority, Center_Group_Name_5, Center_Group_Name_4, Center_Group_Name_3, Center_Group_Name_2, Center_Group_Name_1, Center_Group_Name, Cost_Center_Group, Copy_Cost_Center_Group, Copy_CO_Area, IS_Cost_Center, Vaild_From, Vaild_To, RE_Cost_Center, RE_CO_Area, Name, Description, Person_Responsible, Cost_Center_Category, Hierarchy_Area, Company_Code, Functional_Area, Currency, Profit_Center);
        }
        #endregion


        #region 事件 Tabs切换
        protected void Tabs_Click(object sender, EventArgs e)
        {
            if (((LinkButton)sender).CssClass == "tabs2")
            {
                return;
            }

            #region 初始化
            SetVisible(false, P_VD, P_SA);
            VD_L.CssClass = "tabs1";
            SA_L.CssClass = "tabs1";
            #endregion

            #region Tabs切换动作
            switch (((LinkButton)sender).ID)
            {
                case "VD_L":
                    VD_L.CssClass = "tabs2";
                    P_VD.Visible = true;
                    break;
                case "SA_L":
                    SA_L.CssClass = "tabs2";
                    P_SA.Visible = true;
                    break;
            }
            #endregion
        }
        #endregion

        #region 方法 SetColor
        protected void SetColor()
        {
            SetForeColor(Color.Black, Cost_Center_Group_L, Center_Group_Name_L, IS_Cost_Center_L, Vaild_From_L, Vaild_To_L, Name_L, Description_L, Person_Responsible_L, Cost_Center_Category_L, Functional_Area_L, Hierarchy_Area_L, Company_Code_L, Currency_L, Profit_Center_L);

            switch (Actions.SelectedValue)
            {
                case "1":
                    SetForeColor(Color.Blue, Cost_Center_Group_L, Center_Group_Name_L, IS_Cost_Center_L, Vaild_From_L, Vaild_To_L, Name_L, Description_L, Person_Responsible_L, Cost_Center_Category_L, Functional_Area_L, Hierarchy_Area_L, Company_Code_L, Currency_L, Profit_Center_L);
                    break;

                case "2":
                    SetForeColor(Color.Blue, Cost_Center_Group_L, IS_Cost_Center_L, Center_Group_Name_L, Name_L);
                    break;

                case "3":
                    SetForeColor(Color.Blue, Cost_Center_Group_L, IS_Cost_Center_L, Center_Group_Name_L, Name_L);
                    break;

                case "4":
                    SetForeColor(Color.Blue, Cost_Center_Group_L, IS_Cost_Center_L, Center_Group_Name_L, Name_L);
                    break;
            }
        }
        #endregion

        #region 方法 初始化Tabs
        protected void InitTabs()
        {
            VD_L.Visible = VD.Checked;
            SA_L.Visible = SA.Checked;
           

            SetVisible(false, P_VD, P_SA);
            VD_L.CssClass = "tabs1";
            SA_L.CssClass = "tabs1";
          
            //默认第1个显示 Tabs被选中
            if (VD_L.Visible)
            {
                VD_L.CssClass = "tabs2";
                P_VD.Visible = true;
                return;
            }

            if (SA_L.Visible)
            {
                SA_L.CssClass = "tabs2";
                P_SA.Visible = true;
                return;
            }

      
        }
        #endregion

        #region 方法 SetDefaultValue(设置默认值, 并禁用输入)
        public void SetDefaultValue()
        {
            Center_Group_CO_Area.Text = "3000";
            IS_CO_Area.Text = "3000";
            Record_Quantity.Checked = false;
            Actual_Revenues.Checked = true;
            Plan_Revenues.Checked = true;
            SetEnable(false, Center_Group_CO_Area,IS_CO_Area, Plan_Revenues, Actual_Revenues, Record_Quantity);
            SetForeColor(Color.Orange, Center_Group_CO_Area_L,IS_CO_Area_L, Record_Quantity, Actual_Revenues, Plan_Revenues);
        }
        #endregion
    
        #region 方法 InitDropdownList
        private void InitDropDownList()
        {
            if (!IsLoaded)
            {
                Cost_Center_Category.Items.Clear();
                Cost_Center_Category.Items.Add(new ListItem("", ""));
                IList<m_Center_Category> hys = (m_Center_Category.status == 1).List<m_Center_Category>();
                foreach (m_Center_Category HY in hys)
                {
                    Cost_Center_Category.Items.Add(new ListItem(HY.Cost_Center_Category, HY.Cost_Center_Category));
                }

                Functional_Area.Items.Clear();
                Functional_Area.Items.Add(new ListItem("", ""));
                IList<m_PRC_HK_Functional_Area> fac = (m_PRC_HK_Functional_Area.status == 1).List<m_PRC_HK_Functional_Area>();
                foreach (m_PRC_HK_Functional_Area HY in fac)
                {
                    Functional_Area.Items.Add(new ListItem(HY.Functional_Area, HY.Functional_Area));
                }

                Currency.Items.Clear();
                Currency.Items.Add(new ListItem("", ""));
                IList<m_Cost_Center_Currency> ccc = (m_Cost_Center_Currency.status == 1).List<m_Cost_Center_Currency>();
                foreach (m_Cost_Center_Currency HY in ccc)
                {
                    Currency.Items.Add(new ListItem(HY.Cost_Center_Currency, HY.Cost_Center_Currency));
                }

                Profit_Center.Items.Clear();
                Profit_Center.Items.Add(new ListItem("", ""));
                IList<m_Profit_Center> mpc = (m_Profit_Center.status == 1).List<m_Profit_Center>();
                foreach (m_Profit_Center HY in mpc)
                {
                    Profit_Center.Items.Add(new ListItem(HY.Profit_Center, HY.Profit_Center));
                }

              

                //Center_Group_Name_1.Items.Clear();
                //Center_Group_Name_1.Items.Add(new ListItem("", ""));
                //IList<m_Cost_Center_Group> gec1 = (m_Cost_Center_Group.status == 1).List<m_Cost_Center_Group>();
                //foreach (m_Cost_Center_Group CG1 in gec1)
                //{
                //    Center_Group_Name_1.Items.Add(new ListItem(CG1.Cost_Center_Group, CG1.Cost_Center_Group));
                //}

                //Center_Group_Name_2.Items.Clear();
                //Center_Group_Name_2.Items.Add(new ListItem("", ""));
                //IList<m_Cost_Center_Group> gec2 = (m_Cost_Center_Group.status == 1).List<m_Cost_Center_Group>();
                //foreach (m_Cost_Center_Group CG2 in gec2)
                //{
                //    Center_Group_Name_2.Items.Add(new ListItem(CG2.Cost_Center_Group, CG2.Cost_Center_Group));
                //}

                //Center_Group_Name_3.Items.Clear();
                //Center_Group_Name_3.Items.Add(new ListItem("", ""));
                //IList<m_Cost_Center_Group> gec3 = (m_Cost_Center_Group.status == 1).List<m_Cost_Center_Group>();
                //foreach (m_Cost_Center_Group CG3 in gec3)
                //{
                //    Center_Group_Name_3.Items.Add(new ListItem(CG3.Cost_Center_Group, CG3.Cost_Center_Group));
                //}

                //Center_Group_Name_4.Items.Clear();
                //Center_Group_Name_4.Items.Add(new ListItem("", ""));
                //IList<m_Cost_Center_Group> gec4 = (m_Cost_Center_Group.status == 1).List<m_Cost_Center_Group>();
                //foreach (m_Cost_Center_Group CG4 in gec4)
                //{
                //    Center_Group_Name_4.Items.Add(new ListItem(CG4.Cost_Center_Group, CG4.Cost_Center_Group));
                //}

                Copy_Cost_Center_Group.Items.Clear();
                Copy_Cost_Center_Group.Items.Add(new ListItem("", ""));
                IList<m_Cost_Center_Group_2> ccg2 = (m_Cost_Center_Group_2.status == 1).List<m_Cost_Center_Group_2>();
                foreach (m_Cost_Center_Group_2 HC in ccg2)
                {
                    Copy_Cost_Center_Group.Items.Add(new ListItem(HC.Cost_Center_Group_2, HC.Cost_Center_Group_2));
                }

                //Center_Group_Name_5.Items.Clear();
                //Center_Group_Name_5.Items.Add(new ListItem("", ""));
                //IList<m_Cost_Center_Group> gec5 = (m_Cost_Center_Group.status == 1).List<m_Cost_Center_Group>();
                //foreach (m_Cost_Center_Group CG5 in gec5)
                //{
                //    Center_Group_Name_5.Items.Add(new ListItem(CG5.Cost_Center_Group, CG5.Cost_Center_Group));
                //}


                IsLoaded = true;
            }
        }
        #endregion

        #region 方法 数据验证
        private List<string> DataValidation()
        {
            
            List<string> vald_s = new List<string>();
            List<string> vald_s_2 = new List<string>();
            List<string> vald_s_3 = new List<string>();

           
            List<Regular> regs = new List<Regular>();
            List<Regular> regs1 = new List<Regular>();
            
            
            #region VD
            if (VD.Checked && Actions.SelectedValue == "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, IS_Cost_Center.Text, "Cost center 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Vaild_From.Text, "Vaild From 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Vaild_To.Text, "Vaild To 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Name.Text, "Name 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Description.Text, "Description 必填"));
                //regs.Add(new Regular(RegularExp.NotEmpty, Cost_center_Category.SelectedValue, "Cost center Category 必填"));

                if (RE_Cost_Center.Text == "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, Person_Responsible.Text, "Person Responsible 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, Cost_Center_Category.SelectedValue, "Cost Center Category 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, Hierarchy_Area.Text, "Hierarchy Area 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, Company_Code.SelectedValue, "Company Code 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, Functional_Area.SelectedValue, "Functional Area 必填"));
                    
                    regs.Add(new Regular(RegularExp.NotEmpty, Currency.SelectedValue, "Currency 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, Profit_Center.SelectedValue, "Profit Center 必填"));
                }
            }
            if (VD.Checked && Actions.SelectedValue != "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, IS_Cost_Center.Text, "Cost center 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Name.Text, "Name 必填"));
            }

            vald_s = Validation(regs);
            if (vald_s.Count > 0)
            {
                vald_s.Insert(0, "<font color='#0000FF'><b>Cost Center</b></font>");
            }
            #endregion
       
            #region SA
            regs.Clear();
            if (SA.Checked && Actions.SelectedValue == "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, Cost_Center_Group.Text, "Initial Screen: Cost Center Group 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Center_Group_Name.Text, "Name 必填"));
            }

            if (SA.Checked && Actions.SelectedValue != "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, Cost_Center_Group.Text, "Initial Screen: Cost Center Group 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Center_Group_Name.Text, "Name 必填"));
            }

            vald_s_2 = Validation(regs);
            if (vald_s_2.Count > 0)
            {
                vald_s_2.Insert(0, "<font color='#0000FF'><b>Cost Center Group</b></font>");
                vald_s.AddRange(vald_s_2);
            }
            #endregion




            //if (TaskAPI.Step == "DMO Approve" & Assessment1.Assessment.Opinion == "1")
            //{


            //    regs.Add(new Regular(RegularExp.NotEmpty, DMO_DrpPriority.SelectedValue, " Priority 必填"));
                

            //}
           
        
            //if (TaskAPI.Step == "DMO Approve" & Actions.SelectedValue == "1" & Assessment1.Assessment.Opinion == "1")
            //{
               
            //    if (DMO_Arrpvoe_Creation_Number.Text == "" | DMO_Arrpvoe_Creation_Time.Text == "")
            //    {
            //        regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Approve的Creation项必填"));
            //    }
               
            //}
            //if (TaskAPI.Step == "DMO Maintain" & Actions.SelectedValue == "1" & Assessment1.Assessment.Opinion == "1")
            //{
                
            //    if (DMO_Maintain_Creation_Number.Text == "" | DMO_Maintain_Creation_Time.Text == "")
            //    {
            //        regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Maintain的Creation项必填"));
            //    }

            //}
            //if (TaskAPI.Step == "DMO Check" & Actions.SelectedValue == "1" & Assessment1.Assessment.Opinion == "1")
            //{
            //    if (DMO_Check_Creation_Number.Text == "" | DMO_Check_Creation_Time.Text == "")
            //    {
            //        regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Check的Creation项必填"));
            //    }

            //}
            //if (TaskAPI.Step == "DMO Approve" & Actions.SelectedValue != "1" & Assessment1.Assessment.Opinion == "1")
            //{
            //    if (DMO_Arrpvoe_Revision_Number.Text == "" | DMO_Arrpvoe_Revision_Time.Text == "")
            //    {
            //        regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Approve的Revision项必填"));
            //    }
            //    //if (SA2.Checked & VD_Category.SelectedValue == "1")
            //    //{
            //    //    regs.Add(new Regular(RegularExp.NotEmpty, DMO_SalesSAP_Code.Text, "Sales SAP Code 必填"));
            //    //}
            //}
            //if (TaskAPI.Step == "DMO Maintain" & Actions.SelectedValue != "1" & Assessment1.Assessment.Opinion == "1")
            //{
            //    if (DMO_Maintain_Revision_Number.Text == "" | DMO_Maintain_Revision_Time.Text == "")
            //    {
            //        regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Maintain的Revision项必填"));
            //    }

            //}
            //if (TaskAPI.Step == "DMO Check" & Actions.SelectedValue != "1" & Assessment1.Assessment.Opinion == "1")
            //{
            //    if (DMO_Check_Revision_Number.Text == "" | DMO_Check_Revision_Time.Text == "")
            //    {
            //        regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Check的Revision项必填"));
            //    }

            //}
            
            //vald_s_3 = Validation(regs);
          
            //if (vald_s_3.Count > 0)
            //{
                
            //    vald_s.AddRange(vald_s_3);
            //}
            return vald_s;
      
            
            
           
        }
        #endregion

        #region 重载 OnLoadComplete
        protected override void OnLoadComplete(EventArgs e)
        {
            if (!IsLoaded && TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
            {
                Actions_SelectedIndexChanged(null, e);
            }

            base.OnLoadComplete(e);
        }
        #endregion      

        #region 方法 SetDropDownListValue
        private void SetDropDownListValue(Anthem.DropDownList drpT, object o)
        {
            try
            {
                if ((TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) || drpT.Items.FindByValue(o.ToString()) != null)
                {
                    drpT.SelectedValue = o.ToString();
                    return;
                }

                drpT.Items.Add(new ListItem(o.ToString(), o.ToString()));
                drpT.SelectedIndex = 0;

            }
            catch (Exception)
            {
            }
        }
        #endregion

        #region 事件Cost Center
        protected void RE_Cost_Center_TextChanged(object sender, EventArgs e)
        {
            
            if (Actions.SelectedValue == "1")
            {
                if (RE_Cost_Center.Text != "")
                {
                    SetForeColor(Color.Black, Person_Responsible_L, Cost_Center_Category_L, Hierarchy_Area_L, Company_Code_L, Functional_Area_L, Currency_L, Profit_Center_L);
                }
                else
                {
                    SetForeColor(Color.Blue, Person_Responsible_L, Cost_Center_Category_L, Hierarchy_Area_L, Company_Code_L, Functional_Area_L, Currency_L, Profit_Center_L);
                }
            }
            else
            {
                SetForeColor(Color.Black, Person_Responsible_L, Cost_Center_Category_L, Hierarchy_Area_L, Functional_Area_L, Company_Code_L, Currency_L, Profit_Center_L);
            }

        }
        #endregion

      


    }
}